package top.atluofu.luofuecommerce.search.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import top.atluofu.luofuecommerce.search.service.MallSearchService;
import top.atluofu.luofuecommerce.search.vo.SearchParam;
import top.atluofu.luofuecommerce.search.vo.SearchResult;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName: SearchController
 * @description: TODO
 * @author: 有罗敷的马同学
 * @datetime: 2022Year-11Month-23Day-10:16
 * @Version: 1.0
 */
@Controller
public class SearchController {

    private final MallSearchService mallSearchService;

    @Autowired
    public SearchController(MallSearchService mallSearchService) {
        this.mallSearchService = mallSearchService;
    }

    @GetMapping(value = "/index.html")
    public String listPage(SearchParam param, Model model, HttpServletRequest request) {

        param.set_queryString(request.getQueryString());
        SearchResult result = mallSearchService.search(param);
        model.addAttribute("result", result);
        return "index";
    }


}
